#include <glib.h>

void test_file_utils_mkstemp_func(void)
{
    gchar tmpfile[16] = "/tmp/abcXXXXXX";
    gint fd = 0;
    fd = g_mkstemp(tmpfile);
    g_print("file:%s fd:%d \n", tmpfile, fd);
    
    g_close(fd);
    g_unlink(tmpfile);
}

void test_file_utils_file_open_tmp_func(void)
{
    gint fd = 0;
    gchar tmpfile[16] = "ABCXXXXXX";
    gchar *name_used = NULL;
    GError *error = NULL;

    fd = g_file_open_tmp(tmpfile, &name_used, &error);
    g_print("file:%s fd:%d \n", tmpfile, fd);

    g_close(fd);
    g_unlink(tmpfile);
}

void test_file_utils_mkdtemp_func(void)
{
    gchar tmpdir[32] = "Dir-mkdtemp-XXXXXX";
    gchar *ret = NULL;

    ret = g_mkdtemp(tmpdir);
    g_print("ret: %s, tmpdir: %s \n", ret, tmpdir);
    g_rmdir(tmpdir);
}

gint main(gint argc, gchar **argv)
{
    g_test_init(&argc, &argv, NULL);

    g_test_add_func("/file_utils/mkstemp", test_file_utils_mkstemp_func);
    g_test_add_func("/file_utils/file_open_tmp", test_file_utils_file_open_tmp_func);
    g_test_add_func("/file_utils/mkdtemp", test_file_utils_mkdtemp_func);

    return g_test_run();
}
